package com.springboot.util;

import org.springframework.util.StringUtils;

import java.security.PublicKey;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JieMi {

    private  static String publicKeyStr="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmvXfbj9uZUSicquC2AhpR/KLXX+lCSfY\n" +
            "0LeLxdreWpJerz74B2H0CuzwEnTrIcXPlzLA1cOkiQRDh6YQzLqfeww11noC70C0DlC0U2KwyuMU\n" +
            "5SMue2IIpRNifo5bncsd1gdK1tmrHeL07mkmSuUL27h4kqTXAfo4M47mOw1F7rLK7rg0VOsZ4mta\n" +
            "W5fEWrMCoV+i5uvZ+oGPA44iWpFu9D9IuA/UA/OMoaGu+rGi7XZjmy6GBfCMx+K2UY1Qo3CtO/6p\n" +
            "KADlmeMDakZUuFObqTVsvpTUQjGeH2oqmSdvO5ROpnXrpa5ew8x+gzAJk3YNIa1BH5eKGeGZmkUi\n" +
            "9hZeuwIDAQAB";


    public static Boolean jiemi(String byte2Base64, String sjkd){
        try {
            PublicKey publicKey  = RSAUtil.string2PublicKey(publicKeyStr);
            //加密后的内容Base64解码
            byte[] base642Byte = RSAUtil.base642Byte(byte2Base64);
            //用公钥解密
            byte[] publicDecrypt = RSAUtil.publicDecrypt(base642Byte, publicKey);
            String jijieguo = new String(publicDecrypt);

            if(StringUtils.isEmpty(jijieguo)){
                return false;
            }

            String bidui = jijieguo.substring(3,jijieguo.length());

            SimpleDateFormat dateFormat_3 = new SimpleDateFormat("yyyy-MM-dd");
            Date date1 = dateFormat_3.parse(bidui);

            Date date2 = dateFormat_3.parse(sjkd);

            if(date2.before(date1)){
                return true;
            }else{
                return false;
            }


        }catch (Exception e){
            return  false;
        }

    }

}
